package com.springboot.framework.controller;

import com.springboot.framework.controller.request.SellerUpdateBean;
import com.springboot.framework.controller.request.StatusUpdateBean;
import com.springboot.framework.enums.StatusEnum;
import com.springboot.framework.model.SellerModel;
import com.springboot.framework.service.SellerService;
import com.springboot.framework.utils.ResponseVoUtil;
import com.springboot.framework.vo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author SWF
 * @Date 2019/6/14 21:19
 **/
@Api(description = "【管理员】seller")
@RestController
@RequestMapping("/admin/seller")
public class AdminSellerController {
    @Resource
    private SellerService sellerService;

    @ApiOperation(value = "查看seller列表",notes = "查看seller列表")
    @GetMapping("/list")
    public ResponseVO<List<SellerModel>> list(HttpServletRequest request){
        List<SellerModel> sellerModel = sellerService.list();
        return ResponseVoUtil.success(sellerModel);
    }

    @ApiOperation(value = "修改seller信息",notes = "修改seller信息")
    @PostMapping("/update")
    public ResponseVO<SellerModel> update(@RequestBody SellerUpdateBean bean, HttpServletRequest request){
        SellerModel sellerModel = new SellerModel();
        BeanUtils.copyProperties(bean,sellerModel);
        sellerModel = sellerService.update(sellerModel);
        return ResponseVoUtil.success(sellerModel);
    }

    @ApiOperation(value = "修改seller状态",notes = "修改seller状态")
    @PostMapping("/updateStatus")
    public ResponseVO<SellerModel> update(@RequestBody StatusUpdateBean bean, HttpServletRequest request){
        SellerModel sellerModel = new SellerModel();
        sellerModel.setId(bean.getId());
        sellerModel.setStatus(bean.getStatus());
        sellerModel = sellerService.updateStatus(sellerModel);
        return ResponseVoUtil.success(sellerModel);
    }

    @ApiOperation(value = "删除seller",notes = "删除seller")
    @DeleteMapping("/delete")
    public ResponseVO<SellerModel> delete(@RequestParam Integer sellerId, HttpServletRequest request){
        SellerModel sellerModel = new SellerModel();
        sellerModel.setId(sellerId);
        sellerModel.setStatus(StatusEnum.DELETE.getCode());
        sellerModel = sellerService.update(sellerModel);
        return ResponseVoUtil.success(sellerModel);
    }
}
